<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/9 0009
 * Time: 下午 2:50
 */
namespace app\models;
use app\common\Functions;

use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use yii\data\Pagination;
use yii\data\ActiveDataProvider;
use yii\data\Sort;
use yii\helpers\Inflector;
use yii\db\Expression;

class ContractSearch extends Contract
{
    public function rules()
    {
        return [
            [['contract_name'], 'safe'],
            [['eff_date'], 'safe'],
            [['exp_date'], 'safe'],
            [['context'], 'safe'],


        ];
    }

    public static function tableName()
    {
        return Contract::tableName();
    }


    public function search($params)
    {
        $where = [];
        $query = Contract::find()->alias('a');//合同表
       // $query->joinWith('theSubjects  AS b');// 有表关联,theSubject表
//        $query->joinWith('attrSpecs  AS c');//   特性表的id
//        $query->joinWith('custs  AS e');//客户表
//        $query->joinWith('prodInsts  AS d');/* */




//        $query->where($where);//还没条件传入

//        $query->orderBy(['a.eff_date'=> SORT_DESC]);


        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 50,
            ],
        ]);


//        $sort = $dataProvider->getSort(); // 获取yii自动生成的排序规则
//        $sort->attributes['prod_name'] = [ // 添加用户名的排序规则
//            'asc' => ['d.prod_name' => SORT_ASC],
//            'desc' => ['d.prod_name' => SORT_DESC],
//        ];
//
//        $dataProvider->setSort($sort);

        if (!($this->load($params) )) {
            return $dataProvider;
        }




        return $dataProvider;
    }

}
